<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <label class="el-form-item-label">服务类型</label>
        <el-select v-model="query.svrType" clearable placeholder="请选择">
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
        <label class="el-form-item-label">概要</label>
        <el-input v-model="query.svrTitle" clearable placeholder="概要" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">客户名称</label>
        <el-input v-model="query.svrCustName" clearable placeholder="客户名称" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">服务状态</label>
        <el-input v-model="query.svrStatus" clearable placeholder="服务状态" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <!--    <div class="block">
          <span class="demonstration">带快捷选项</span>
          {{ query.svrCreateDate }}
          <el-date-picker
            v-model="query.svrCreateDate"
            type="daterange"
            align="right"
            unlink-panels
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            :picker-options="pickerOptions2"
            value-format="yyyy-MM-dd HH:mm:ss"
          />
        </div> -->
        <!-- <div class="block">
          <span class="demonstration">时间戳</span>
          <div class="demonstration">值：{{ value12 }}</div>
          <el-date-picker
            v-model="query.svrCreateDate"
            type="date"
            placeholder="选择日期"
            format="yyyy 年 MM 月 dd 日"
            value-format="timestamp"
          />
        </div> -->
        <!--  <date-range-picker
          v-model="query.svrCreateDate"
          start-placeholder="2022-06-03 18:15:54"
          end-placeholder="2022-06-03 18:42:41"
          class="date-item"
        /> -->
        <rrOperation :crud="crud" />
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="500px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
          <!--    <el-form-item label="分配给的员工编号">
            <el-input v-model="form.svrDueId" style="width: 370px;" />
          </el-form-item> -->
          <el-form-item v-show="false" label="服务状态" prop="svrStatus">
            <span style="color: aqua;">{{ form.svrStatus="已分配" }}</span>
          </el-form-item>
          <el-form-item label="分配给:" prop="svrDueTo">
            <el-input v-model="form.svrDueTo" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="分配时间">
            <el-date-picker v-model="form.svrDueDate" type="datetime" style="width: 370px;" />
            <!-- {{ form.svrDueDate= new Date() }} -->
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column prop="svrId" label="编号" />

        <el-table-column prop="svrTitle" label="概要" />
        <el-table-column prop="svrCustNo" label="客户编号" />
        <el-table-column prop="svrCustName" label="客户名称" />
        <el-table-column prop="svrStatus" label="服务状态">
          <template slot-scope="scope">
            {{ dict.label.svr_status[scope.row.svrStatus] }}
          </template>
        </el-table-column>
        <el-table-column prop="svrRequest" label="服务请求" />
        <el-table-column prop="svrCreateId" label="创建人编号" />
        <el-table-column prop="svrCreateBy" label="创建人名称" />
        <el-table-column prop="svrCreateDate" label="创建时间" />
        <el-table-column prop="svrType" label="服务类型">
          <template slot-scope="scope">
            {{ dict.label.svr_type[scope.row.svrType] }}
          </template>
        </el-table-column>
        <!-- <el-table-column prop="svrDueId" label="分配给的员工编号" /> -->
        <el-table-column v-if="checkPer(['admin','sctService:edit','sctService:del'])" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudSctService from '@/api/sctService'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'

const defaultForm = { svrId: null, svrType: null, svrTitle: null, svrCustNo: null, svrCustName: null, svrStatus: null, svrRequest: null, svrCreateId: null, svrCreateBy: null, svrCreateDate: null, svrDueId: null, svrDueTo: null, svrDueDate: null, svrDeal: null, svrDealId: null, svrDealBy: null, svrDealDate: null, svrResult: null, svrSatisfy: null, isDelete: null }
export default {
  name: 'SctService1',
  components: { pagination, crudOperation, rrOperation, udOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  dicts: ['svr_type', 'svr_status', 'cust_satisfy'],
  cruds() {
    return CRUD({ queryOnPresenterCreated: false, title: '客户服务', url: 'api/sctService', idField: 'svrId', sort: 'svrId,desc', crudMethod: { ...crudSctService }})
  },
  data() {
    return {
      pickerOptions2: {
        shortcuts: [{
          text: '最近一周',
          onClick(picker) {
            const end = new Date()
            const start = new Date()
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7)
            picker.$emit('pick', [start, end])
          }
        }, {
          text: '最近一个月',
          onClick(picker) {
            const end = new Date()
            const start = new Date()
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30)
            picker.$emit('pick', [start, end])
          }
        }, {
          text: '最近三个月',
          onClick(picker) {
            const end = new Date()
            const start = new Date()
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90)
            picker.$emit('pick', [start, end])
          }
        }]
      },
      options: [{
        value: '1',
        label: '咨询'
      }, {
        value: '2',
        label: '投诉'
      }, {
        value: '3',
        label: '建议'
      }],
      permission: {
        add: ['admin', 'sctService:add'],
        edit: ['admin', 'sctService:edit'],
        del: ['admin', 'sctService:del']
      },
      rules: {
        svrDueTo: [
          { required: true, message: '处理人不能为空', trigger: 'blur' }
        ]
      },
      queryTypeOptions: [
        { key: 'svrType', display_name: '服务类型' },
        { key: 'svrTitle', display_name: '概要' },
        { key: 'svrCustNo', display_name: '客户编号' },
        { key: 'svrCustName', display_name: '客户名称' },
        { key: 'svrStatus', display_name: '服务状态' },
        { key: 'svrDueId', display_name: '分配给的员工编号' },
        { key: 'svrDueTo', display_name: '分配给的员工姓名	' },
        { key: 'svrSatisfy', display_name: '满意度' }
      ]
    }
  },
  created() {
    this.crud.params = { svrStatus: '新创建' }
    this.crud.toQuery()
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    }
  }
}
</script>

<style scoped>

</style>
